package com.leedsoft.spittr.service;

import com.leedsoft.generated.Users;
import com.leedsoft.generated.UsersExample;
import com.leedsoft.generated.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by leeds on 2017/11/14.
 */
@Service
public class DataService {
    @Autowired
    private UsersMapper usersMapper;

    public List<Users> getUsersList() {
        return usersMapper.selectByExample(new UsersExample());
    }

    @Transactional
    public void insertOne() {
        Users u = new Users();
        u.setUsername("一可可一");
        u.setPassword("yikekeyi...");
        u.setEnabled(0);
        usersMapper.insert(u);
        throw new RuntimeException("会滚吧");
    }
    private @Value("${jdbc.url}") String username;
    private @Value("${jdbc.driver}") String driver;
    private @Value("111111${lizi.go}") String lizi;
    public void noTx() {
        //read 、单表更新且更新完毕不会抛出异常的方法，都可以不用开启数据库事务
        Users u = new Users();
        u.setUsername("一可可一");
        u.setPassword("yikekeyi...");
        u.setEnabled(0);
        usersMapper.insert(u);
        System.out.println("这是不用开启事务的Service 方法哦");
        System.out.println(username);
        System.out.println(driver);
        System.out.println(lizi);
    }

    public static void main(String[] args) {
        System.getProperties().list(System.out);
    }
}
